import fs from "fs";
import { localConfigName } from "../constants";
import getLocalConfig from "./getLocalConfig";

const saveLocalConfig = async (_, key, value) => {
    const data = {
        [key]: value
    };
    if (!fs.existsSync(localConfigName)) {
        fs.writeFileSync(localConfigName, JSON.stringify(data, '\n', 4));
    } else {
        const source = await getLocalConfig();
        fs.writeFileSync(localConfigName, JSON.stringify({
            ...source,
            ...data,
        }, '\n', 4));
    }

}


export default saveLocalConfig;